﻿using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace EmoneyWeiXinThreadDAL
{
    public class PropellingLogDAL
    {
        public int getPropellingUpdate(PropellingLogEntity porpeEn)
        {
            string sql = "";
            if (porpeEn.id > 0)
            {
                sql = " update PropellingLog set weixinid='" + porpeEn.weixinid + "',newsreportid='" + porpeEn.newsreportid + "',ToUsername='" + porpeEn.ToUsername + "',errorResult='" + porpeEn.errorResult + "',updatetime='" + porpeEn.updatetime + "' where id=" + porpeEn.id;
            }
            else
            {
                sql = " insert into PropellingLog(weixinid, newsreportid, ToUsername, errorResult, updatetime) values('" + porpeEn.weixinid + "','" + porpeEn.newsreportid + "','" + porpeEn.ToUsername + "','" + porpeEn.errorResult + "','" + porpeEn.updatetime + "')";
            }
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, null);
        }

        public void getStockdictor(string sid, string str, string weixinid, string fz = "")
        {
            if (!string.IsNullOrEmpty(fz))
            {
                if (fz == "dtw")
                {
                    fz = "多图文";
                }
                else if (fz == "voice")
                {
                    fz = "voice";
                }
                else if (fz == "付费")
                {
                    fz = "付费";
                }
                else
                {
                    fz = "群发";
                }
                SQLTools tools = new SQLTools();
                tools.AddSqlParameter("result", SqlDbType.VarChar, 100000, str);
                string sql = "INSERT INTO dbo.StockDoctorlog(weixinid, newsreportid, wType, FromUserName, ToUserName, CONTENT, eventkey, updatetime, Stock, result)";
                sql += " values(" + weixinid + ",0,10,'" + sid + "','','" + fz + "','',getdate(),'',@result)";
                SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, tools.GetSqlParameters());
            }
            else
            {
                if (!string.IsNullOrEmpty(sid) && !string.IsNullOrEmpty(str))
                {
                    string sql = "INSERT INTO dbo.StockDoctorlog(weixinid, newsreportid, wType, FromUserName, ToUserName, CONTENT, eventkey, updatetime, Stock, result)";
                    sql += " SELECT weixinid,newsreportid,10 wType,FromUserName,ToUserName,CONTENT,eventkey,GETDATE() updatetime,Stock,'" + str + "' result FROM StockDoctorlog WITH(NOLOCK) WHERE id='" + sid + "'";
                    //string sql = "update StockDoctorlog set result=result+'^^^" + str + "' where id=" + sid;
                    SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, null);
                }
            }
        }
    }
}
